using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class Singal
{

}
public class CsharpSingal<T> where T :class,new()
{
    static private T m_instance;
    static public T Instance
    {
        get 
        {
            if (m_instance == null)
            {
                m_instance = new T();
            }    
            return m_instance; 
        }
    }
}

public class UnitySingal<T> : MonoBehaviour where T : Component
{
    static private T m_instance;
    static public T Instance
    {
        get
        {
            m_instance = FindObjectOfType<T>();
            if(m_instance == null)
            {
                GameObject go = new GameObject(typeof(T).ToString());
                m_instance = go.AddComponent<T>();
            }

            return m_instance;
        }
    }

    public virtual void Awake()
    {
        // if(m_instance!=null)
        // {
        //     GameObject.Destroy(this.gameObject);
        //     return;
        // }
        DontDestroyOnLoad(this.gameObject);
        Init();
    }

    public virtual void Init() { }
}
    
    

